
#include "comm.hpp"

int main()
{
    // 1、创建公共的key值
    key_t k = ftok(PATH_NAME, PROJ_ID);
    if (k < 0)
    {
        Log("client:ftok failure!", Error)<< " clinet key: " << k << endl;
        exit(1);
    }
    Log("client:ftok success", Debug) << " clinet key: " << k << endl;


    //2、获取共享内存
    int shmid = shmget(k, SHM_SIZE, IPC_CREAT);//若创建的共享内存在底层存在，则获取并返回
        if( shmid < 0)
    {
        Log("client: get shm failure!", Error) << " the shmid:" << shmid << endl;
        exit(2);
    }
    Log("client: get shm success", Debug) << " the shmid:" << shmid << endl;


    //3、建立映射（关联）
    char* shmaddr = (char*)shmat(shmid, nullptr, 0);
    Log("client: attach shm success", Debug) << " the shmaddr: "<< shmaddr << endl;
    

    //4、进行通信


    //5、取消映射（去关联）
    int ret = shmdt(shmaddr);
    assert( ret != -1);
    Log("client: detach shm success", Debug) << " the ret: " << ret << endl;


    //6、server中做了处理，此处不用删除共享内存

    return 0;
}